package com.xyy.saas.payment.service.impl;

import com.xyy.saas.payment.dao.mapper.WXPayRecordMapper;
import com.xyy.saas.payment.dao.model.BankPayRecord;
import com.xyy.saas.payment.dao.model.WXPayRecord;
import com.xyy.saas.payment.service.WXPayRecordService;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import javax.annotation.Resource;
import java.util.Objects;

@Service
public class WXPayRecordServiceImpl implements WXPayRecordService {
    @Resource
    private WXPayRecordMapper wxPayRecordMapper;

    @Override
    public WXPayRecord queryByPayNo(String payNo) {
        if(StringUtils.isEmpty(payNo)) {
            return null;
        }

        return wxPayRecordMapper.queryByPayNo(payNo);
    }

    @Override
    public WXPayRecord queryByBusinessNo(String businessNo) {
        if(StringUtils.isEmpty(businessNo)) {
            return null;
        }

        return wxPayRecordMapper.queryByBusinessNo(businessNo);
    }

    @Override
    public int save(WXPayRecord bankPayRecord) {
        if(Objects.isNull(bankPayRecord)) {
            return 0;
        }

        return wxPayRecordMapper.insertSelective(bankPayRecord);
    }

    @Override
    public int updateByPayNo(WXPayRecord wxPayRecord) {
        if(Objects.isNull(wxPayRecord)) {
            return 0;
        }

        if(StringUtils.isEmpty(wxPayRecord.getPayNo())) {
            return 0;
        }

        return wxPayRecordMapper.updateByPayNo(wxPayRecord);
    }

    /**
     * 更新记录
     *
     * @param wxPayRecord
     * @return
     */
    @Override
    public int updateById(WXPayRecord wxPayRecord) {
        if(Objects.isNull(wxPayRecord)) {
            return 0;
        }

        if(wxPayRecord.getId() == null) {
            return 0;
        }

        return wxPayRecordMapper.updateById(wxPayRecord);
    }
}
